from .setting import *
from django.http import HttpResponse
import requests
from json

#损坏资产添加对接接口
def damage_add(request):
    if request.method == 'POST':
        info = request.POST
        url = url_api + 'asset/damage_asset_add/'
        date = {'tower_name':info['tower_num'],'floor_num':info['floor_num'],
                'room_num':info['room_num'],'asset_name':info['asset_num'],
                'verify_pswd':123}

        r = requests.post(url,data=data)

        if json.load(r)['message'] == '添加成功':
            return HttpResponse('添加成功')
        else:
            return HttpResponse('添加失败')
    elif request.method == 'GET':
        return HttpResponse('获取有误')

#损坏资产查询对接接口
def damage_add(request):
    if request.method == 'POST':
        info = request.POST
        url = url_api + 'asset/damage_asset_add/'
        date = {'room_num':info['room_num'],'asset_name':info['asset_num'],
                'verify_pswd':123}

        r = requests.post(url,data=data)

        if json.load(r)['message'] == '没有记录':
            return HttpResponse('没有记录')
        else:
            info_dict = json.load(r)['message']
            context = {'aa':info_dict}
            return render(request,'asset/damage_find.html',context)
    elif request.method == 'GET':
        return HttpResponse('获取有误')

#损坏资产删除对接接口
def damage_add(request):
    if request.method == 'POST':
        info = request.POST
        url = url_api + 'asset/damage_asset_add/'
        date = {'room_num':info['room_num'],'asset_name':info['asset_num'],
                'verify_pswd':123}

        r = requests.post(url,data=data)

        if json.load(r)['message'] == '添加成功':
            return HttpResponse('添加成功')
        else:
            return HttpResponse('添加失败')
    elif request.method == 'GET':
        return HttpResponse('获取有误')
